package com.fjb.service.user.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fjb.common.entity.HttpCode;
import com.fjb.common.entity.JsonTotalResult;
import com.fjb.common.entity.PageQuery;
import com.fjb.common.enums.user.UserType;
import com.fjb.common.global.GlobalConfig;
import com.fjb.mapper.user.SysUserFileMapper;
import com.fjb.pojo.user.SysUser;
import com.fjb.pojo.user.SysUserFile;
import com.fjb.pojo.user.query.SysUserFileQuery;
import com.fjb.pojo.user.vo.SysUserFileVo;
import com.fjb.service.user.SysUserFileService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * <p>
 * 用户文件 服务实现类
 * </p>
 *
 * @author hemiao
 * @since 2019-12-22
 */
@Service
public class SysUserFileServiceImpl extends ServiceImpl<SysUserFileMapper, SysUserFile> implements SysUserFileService {
	
	@Autowired
	private SysUserFileMapper sysUserFileMapper;
	
	@Override
	public JsonTotalResult<List<SysUserFileVo>> selectPageList(PageQuery pageQuery, SysUserFileQuery userFileQuery) {
		PageHelper.startPage(pageQuery.getCurrentPage(), pageQuery.getPageSize());
		List<SysUserFileVo> infoList = sysUserFileMapper.selectPageList(userFileQuery);
		if(infoList.size()>0) {
			for (SysUserFileVo file : infoList) {
				String fileUrl = file.getFileUrl();
				if(StringUtils.isNotBlank(fileUrl)) {	
					file.setFileUrl(GlobalConfig.FILE_SERVICE_LOCATION+fileUrl);
				}
			}
		}
		PageInfo<SysUserFileVo> pageInfo = new PageInfo<SysUserFileVo>(infoList);	
		return new JsonTotalResult<List<SysUserFileVo>>(infoList, HttpCode.SUCCESS, pageInfo.getTotal());
	}

}
